// @Author EthanScriptOn
// @Desc
package log_queue

import "errors"

type LogQueue struct {
	logData        chan interface{}
	isClose        bool
	processedTasks int
	tasksTotal     int
}

func GenerateLogQueue() *LogQueue {
	return &LogQueue{
		logData: make(chan interface{}, 1024),
	}
}

func (l *LogQueue) Pull() (interface{}, error) {
	select {
	case data, ok := <-l.logData:
		if !ok {
			return nil, errors.New("log queue closed")
		}
		l.processedTasks++
		return data, nil
	}
}

func (l *LogQueue) Push(data interface{}) {
	l.logData <- data
	l.tasksTotal++
}

func (l *LogQueue) Close() {
	l.isClose = true
	close(l.logData)
}

func (l *LogQueue) IsClose() bool {
	return l.isClose
}

func (l *LogQueue) QueueCap() int {
	return cap(l.logData)
}

func (l *LogQueue) QueueLen() int {
	return len(l.logData)
}

func (l *LogQueue) ProcessedTasks() int {
	return l.processedTasks
}

func (l *LogQueue) TasksTotal() int {
	return l.tasksTotal
}
